package com.bdsy.business.controller;

import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.bdsy.api.annotation.IgnoreAuth;
import com.bdsy.business.model.Order;
import com.bdsy.business.model.ReceiveGood;
import com.bdsy.business.service.ReceiveGoodService;
import com.bdsy.common.annotation.Json;
import com.bdsy.common.utils.Result;
import com.bdsy.system.annotation.SysLog;

/**
 * 收货信息
 * @author MING
 * @date 2018年1月4日 下午4:37:14
 */

@Controller
@RequestMapping(value = {"${web.adminPath}", "${web.appPath}"})
public class ReceiveGoodController {

	@Autowired
	ReceiveGoodService receiveGoodService;

	/**
	 * 查询收货地址信息
	 */
	@IgnoreAuth
	@Json
	@RequestMapping(value = "receiveGoodListById")
	public Object receiveGoodListById(String userId) {
		
		Map<String,Object> map = new LinkedHashMap<>();
		List<ReceiveGood> receiveGoodList = receiveGoodService.receiveGoodListById(userId);
		map.put("code", 200);
		map.put("msg", "success");
		map.put("data", receiveGoodList);
		return map;
	}
	
	
	/**
	 * 添加收货地址信息
	 */
	@IgnoreAuth
	@Json
	@RequestMapping(value = "addReceiveGood")
	public Object addReceiveGood(ReceiveGood receiveGood) {
		
		boolean result = receiveGoodService.add(receiveGood);
		if (result) {
			return Result.ok("addSuccess");
		} else {
			return Result.error("addFail");
		}
	}
	
	/**
	 * 修改收货地址信息
	 */
	@IgnoreAuth
	@Json
	@RequestMapping(value = "updateReceiveGood")
	public Object updateReceiveGood(ReceiveGood receiveGood) {
		boolean result = receiveGoodService.update(receiveGood);
		if (result) {
			return Result.ok("updateSuccess");
		} else {
			return Result.error("updateFail");
		}
	}
	
	/**
	 * 删除收货地址信息
	 */
	@IgnoreAuth
	@Json
	@RequestMapping(value = "deleteReceiveGood")
	public Object deleteReceiveGood(int reId) {
		
		boolean result = receiveGoodService.delete(reId);
		if (result) {
			return Result.ok("deleteSuccess");
		} else {
			return Result.error("deleteFail");
		}
	}
	
}
